<?php
$header = array("ID","名称","分类","路径","封面地址","备注","增加时间","更新时间");
function filter_ebook(&$v,$k) {
	foreach($v as $key=>$val) {
		if(function_exists("ebook_".$key)) {
			$func = "ebook_".$key;
			$v[$key] = $func($val);
		}
	}
}
array_walk($ebooks,"filter_ebook");

echo "<table>";
echo "<tbody>";
foreach($ebooks as $ebook) {
	echo "<tr>";
	foreach($ebook as $k=>$v) {
		echo "<td>".$v."</td>";
	}
	echo "</tr>";
}
echo "</tbody>";
echo "</table>";
?>
<script type="text/javascript">
var dataModel =  [
				{display: 'ID', name : 'id', width : 30, sortable : true, align: 'center'},
				{display: '书名', name : 'ebook_name', width : 320, sortable : true, align: 'left'},
				{display: '分类', name : '', width : 50, sortable : true, align: 'center'},
				{display: '路径', name : '', width : 130, sortable : true, align: 'center'},
				{display: '封面地址', name : '', width : 140, sortable : true, align: 'center', hide: true},
				{display: '备注',name:'memo',width:40,sortable:false,align:'center', hide: true},
				{display: '创建时间',name:'create',width:80,sortable:true,align:'center', hide: true}
				];
	$("table").flexigrid({
		height:300,
		novstripe:true,
		url:"http://<?php echo site_url("ebook/get");?>",
		dataType: 'json',
		colModel : dataModel,
		buttons : [
			{name:'修改',bclass:'edit',onpress:e_edit},
			{name: '增加', bclass: 'add', onpress : ""},
			{name: '删除', bclass: 'delete', onpress:""},
			{separator: true}
			],
		searchitems : [
			{display: '电子书名', name : 'ebook_name',isdefault:true}
			],
		title: 'Ebook - 电子书',
		useRp: true,
		rp: 10,
		sortname:'id',
		sortorder:'asc',
		blockOpacity:0.2,
		showTableToggleBtn: true,
		usepager:true
	});

function e_edit(com,grid) {
	//从HTML里抽离出数据构造修改表单
	$('.trSelected div',grid).each(function(i,n) {
		alert($(n).html());
	});
}
</script>